package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * 商品详情
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 详情请求
     */
    @GetMapping("/item/{id}.html")
    public String showDetail(@PathVariable("id") Long id,Model model){
        //获取商品详情需要的数据
        /**
         * key：参数的别名
         * value： 参数值
         */
        Map<String,Object> resultMap = pageService.getDetailData(id);
        //给页面传递数据
        model.addAllAttributes(resultMap);
        /**
         * resultMap.entrySet.forEach(entry->{
             model.addAttribute(entry.getKe(),entry.getValue);
            })
         */
        //返回模块页面
        return "item";
    }

}
